import Vue from "vue";
import axios from "axios";
 
 
// 添加请求拦截器  拦截器拦截了一些信息给axios  拦截在 config.headers 里面
axios.interceptors.request.use(
    function(config) {
        let host = "";
        //  http.defaults.headers.info='info'
        let info = config.headers.info;
        console.log('此时来到了api文件夹下的http')
        console.log('info',info)
        if ("info" == info) {
            // 详情页面的头
            host = "mall.film-ticket.film.info";
        } else if ("cinema" == info) {
            // 影院列表
            host = "mall.film-ticket.cinema.list";
            //有城市的数据
        } else if ("city" == info) {
            host = "mall.film-ticket.city.list";
        } else {
            // 列表信息的头
            host = "mall.film-ticket.film.list";
        }
        //   X-Host: mall.film-ticket.film.info
        config.headers = {
            "X-Client-Info":   '{"a":"3000","ch":"1002","v":"5.0.4","e":"1598087896889693885431809","bc":"110100"}',
            "X-Host": host,
        };
        return config;
    },
    function(error) {
        // 对请求错误做些什么
        return Promise.reject(error);
    }
);

export default axios;